package com.hdu.dwh.dtos.cdc_dtos;

import com.hdu.dwh.utils.CDCUtils;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.util.List;

@Data
@EqualsAndHashCode(callSuper = true)
public class MongocdcDtos extends FlinkJobDto {

    public MongocdcDtos(){}

    public MongocdcDtos(String hosts, String username, String password, String database, String collection, String targetDatabaseName, String targetTableName) {
        this.hosts = hosts;
        this.username = username;
        this.password = password;
        this.database = database;
        this.collection = collection;
        this.targetDatabase = targetDatabaseName;
        this.targetTable = targetTableName;
    }

    @Schema(hidden = true)
    private String entryClass = "org.apache.paimon.flink.action.FlinkActions";

    @Schema(description = "mongodb连接地址", defaultValue = "127.0.0.1:27017")
    private String hosts;

    @Schema(description = "mongodb用户名", defaultValue = "")
    private String username;

    @Schema(description = "mongodb密码", defaultValue = "")
    private String password;

    @Schema(description = "mongodb数据库名")
    private String database;

    @Schema(description = "mongodb集合名")
    private String collection;

    @Schema(description = "paimon数据库名", defaultValue = "default")
    private String targetDatabase;

    @Schema(description = "paimon表名")
    private String targetTable;

    @Schema(hidden = true)
    public List<String> getMongoCDCConfigList() {
        if (this.hosts == null || this.database == null || this.collection == null || this.targetDatabase == null || this.targetTable == null) {
            throw new IllegalArgumentException("参数不能为空" + this.toString());
        }
        List<String> config = CDCUtils.buildMongoCDCParamList(hosts, username, password, database, collection, targetDatabase, targetTable);
        return config;
    }
}
